//
//  MYGPatientShareView.swift
//  MYDoctor
//
//  Created by 王振明 on 2024/4/18.
//

import UIKit

class MYGPatientShareView: UIView {

    var copyBlock:voidBlock?
    var sendBlock:voidBlock?
    var closeBlock:voidBlock?

    override init(frame: CGRect) {
        super.init(frame: frame)
        initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    @objc func cancelAction(){
        if (self.copyBlock != nil){
            self.copyBlock!()
        }
    }
    @objc func sureAction(){
        if (self.sendBlock != nil){
            self.sendBlock!()
        }
    }
    @objc func closeAction(){
        if (self.closeBlock != nil){
            self.closeBlock!()
        }
    }
    func initUI(){
        addSubview(backV)
        backV.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(bottomSafeheight + 158)
        }
        backV.addSubviews([titleLab,copyBtn,sendBtn,closeBtn,copyLab,sendLab])
        titleLab.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(33)
            make.top.equalToSuperview().offset(21)
            make.height.equalTo(22.5)
        }
        closeBtn.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-12)
            make.top.equalToSuperview().offset(12)
            make.height.width.equalTo(13)
        }
        copyBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(33)
            make.top.equalTo(titleLab.snp.bottom).offset(15)
            make.height.width.equalTo(50)
        }
        sendBtn.snp.makeConstraints { make in
            make.left.equalTo(copyBtn.snp.right).offset(33)
            make.top.equalTo(titleLab.snp.bottom).offset(15)
            make.height.width.equalTo(50)
        }
        
        copyLab.snp.makeConstraints { make in
            make.centerX.equalTo(copyBtn)
            make.top.equalTo(copyBtn.snp.bottom).offset(5.5)
            make.height.width.equalTo(18.5)
        }
        sendLab.snp.makeConstraints { make in
            make.centerX.equalTo(sendBtn)
            make.top.equalTo(sendBtn.snp.bottom).offset(5.5)
            make.height.width.equalTo(18.5)
        }
    }
    private lazy var backV: UIView = {
        let cont = UIView()
        cont.backgroundColor = .white
        cont.layerCornerRadius = 12
        return cont
    }()
    lazy var titleLab: UILabel = {
        let cont = UILabel()
        cont.text = "邀请患者完善病例"
        cont.font = .regular(17)
        cont.textColor = .rgba(54, 54, 54, 1)
        return cont
    }()
    private lazy var copyBtn:UIButton = {
       let vi = UIButton()
        vi.setImage(UIImage(named: "patientShare_copy"), for: .normal)
        vi.addTarget(self, action: #selector(cancelAction), for: .touchUpInside)
        return vi
    }()
    private lazy var sendBtn:UIButton = {
       let vi = UIButton()
        vi.setImage(UIImage(named: "patientShare_send"), for: .normal)
        vi.addTarget(self, action: #selector(sureAction), for: .touchUpInside)
        return vi
    }()
    private lazy var closeBtn:UIButton = {
       let vi = UIButton()
        vi.setImage(UIImage(named: "patientShare_close"), for: .normal)
        vi.addTarget(self, action: #selector(closeAction), for: .touchUpInside)
        return vi
    }()
    lazy var copyLab: UILabel = {
        let cont = UILabel()
        cont.text = "复制链接"
        cont.font = .regular(13)
        cont.textColor = .rgba(35, 35, 35, 1)
        return cont
    }()
    lazy var sendLab: UILabel = {
        let cont = UILabel()
        cont.text = "发送短信"
        cont.font = .regular(13)
        cont.textColor = .rgba(35, 35, 35, 1)
        return cont
    }()
}
class MYGPatientDetailShareView: UIView {

    var nextBlock:((Int) -> ())?
    var dismissBlock:(() -> ())?
    var patientId:Int = 0
    override init(frame: CGRect) {
        super.init(frame: frame)
        initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    @objc func cancelAction(){
        if let c = dismissBlock {
            c()
        }
    }
    @objc func sureAction(){
        if let c = nextBlock {
            c(patientId)
        }
//        cancelAction()
//        let selectPatientView = MYGCaseFileSelectView()
//        MYGPatientDetailViewController.keyWindow?.addSubview(selectPatientView)
//        selectPatientView.snp.makeConstraints { make in
//            make.edges.equalToSuperview()
//        }
//        if let c = dismissBlock {
//            c()
//        }
    }
    @objc func selectBingli(){
        bingliBtn.isSelected = true
        shoushuBtn.isSelected = false
    }
    @objc func selectshoushu(){
        bingliBtn.isSelected = false
        shoushuBtn.isSelected = true
    }
    func initUI(){
        self.backgroundColor = .rgba(0, 0, 0,0.6)
        addSubview(backV)
        backV.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.left.equalToSuperview().offset(17.5)
            make.right.equalToSuperview().offset(-17.5)
            make.height.equalTo(206)
        }
        backV.addSubviews([titleLab,bingliBtn,bingliLab,shoushuBtn,shoushuLab,cancelBtn,sureBtn])
        self.layoutIfNeeded()
        backV.layoutIfNeeded()
        titleLab.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(19)
            make.height.equalTo(24)
        }
        bingliLab.snp.makeConstraints { make in
            make.centerX.equalToSuperview().offset(-(screenWidth - 35)/4)
            make.centerY.equalToSuperview()
            make.height.equalTo(22.5)
        }
        bingliBtn.snp.makeConstraints { make in
            make.right.equalTo(bingliLab.snp.left).offset(-10)
            make.centerY.equalTo(bingliLab)
            make.height.width.equalTo(15)
        }
        shoushuLab.snp.makeConstraints { make in
            make.centerX.equalToSuperview().offset((screenWidth - 35)/4)
            make.centerY.equalToSuperview()
            make.height.equalTo(22.5)
        }
        
        shoushuBtn.snp.makeConstraints { make in
            make.right.equalTo(shoushuLab.snp.left).offset(-10)
            make.centerY.equalTo(bingliLab)
            make.height.width.equalTo(15)
        }
        backV.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.bottom.equalToSuperview()
            make.height.equalTo(50)
            make.width.equalTo((screenWidth - 35)/2)
        }
        backV.addSubview(sureBtn)
        sureBtn.snp.makeConstraints { make in
            make.right.equalToSuperview()
            make.bottom.equalToSuperview()
            make.height.equalTo(50)
            make.width.equalTo((screenWidth - 35)/2)
        }
    }
    private lazy var backV: UIView = {
        let cont = UIView()
        cont.backgroundColor = .white
        cont.layerCornerRadius = 12
        return cont
    }()
    lazy var titleLab: UILabel = {
        let cont = UILabel()
        cont.text = "分享"
        cont.font = .regular(17)
        cont.textColor = .rgba(54, 54, 54, 1)
        return cont
    }()
    private lazy var bingliBtn:UIButton = {
       let vi = UIButton()
        vi.setImage(UIImage(named: "Chat/Menu/circle"), for: .normal)
        vi.setImage(UIImage(named: "Chat/Menu/circle_sel"), for: .selected)
        vi.addTarget(self, action: #selector(selectBingli), for: .touchUpInside)
        vi.isSelected = true
        return vi
    }()
    private lazy var shoushuBtn:UIButton = {
       let vi = UIButton()
        vi.setImage(UIImage(named: "Chat/Menu/circle"), for: .normal)
        vi.setImage(UIImage(named: "Chat/Menu/circle_sel"), for: .selected)
        vi.addTarget(self, action: #selector(selectshoushu), for: .touchUpInside)
        return vi
    }()
//    private lazy var cancelBtn:UIButton = {
//       let vi = UIButton()
//        vi.setImage(UIImage(named: "patientShare_close"), for: .normal)
//        vi.addTarget(self, action: #selector(closeAction), for: .touchUpInside)
//        return vi
//    }()
    lazy var bingliLab: UILabel = {
        let cont = UILabel()
        cont.text = "分享患者病例"
        cont.font = .medium(16)
        cont.textColor = .rgba(70, 70, 70, 1)
        return cont
    }()
    lazy var shoushuLab: UILabel = {
        let cont = UILabel()
        cont.text = "分享患者手术"
        cont.font = .medium(16)
        cont.textColor = .rgba(70, 70, 70, 1)
        return cont
    }()
    private lazy var cancelBtn:UIButton = {
       let vi = UIButton()
        vi.setTitle("取消", for: .normal)
        vi.titleLabel?.font = .regular(17)
        vi.setTitleColor(.rgba(102, 102, 102), for: .normal)
        vi.addTarget(self, action: #selector(cancelAction), for: .touchUpInside)
        vi.layer.borderWidth = 0.5
        vi.layer.borderColor = RGBA(r: 212, g: 212, b: 212, a: 1).cgColor
        return vi
    }()
    private lazy var sureBtn:UIButton = {
       let vi = UIButton()
        vi.setTitle("下一步", for: .normal)
        vi.titleLabel?.font = .regular(17)
        vi.setTitleColor(.rgba(69, 131, 250, 1), for: .normal)
        vi.addTarget(self, action: #selector(sureAction), for: .touchUpInside)
        vi.layer.borderWidth = 0.5
        vi.layer.borderColor = RGBA(r: 212, g: 212, b: 212, a: 1).cgColor
        return vi
    }()
    
}
